#pragma once
#include <list>
#include <d3d10.h>
#include "IEngineSystem.h"
#include "WindowSystem.h"
#include "ItemDator.h"

// {AF84B087-371E-431b-828D-B1F0E27B1C0E}
DEFINE_GUID(HARDWARE_SYSTEM_GUID, 
0xaf84b087, 0x371e, 0x431b, 0x82, 0x8d, 0xb1, 0xf0, 0xe2, 0x7b, 0x1c, 0xe);

class HardwareSystem : public IEngineSystem
{
public:
	HardwareSystem(EnginePointer<SettingsManager>& settings, EnginePointer<IMessageQueue>& messages);
	~HardwareSystem(void);

	HRESULT Initialize(EnginePointer<SystemCollection>& systems);
	void DeliverMessage(Message& m);
	BOOL IsClean();
	GUID getSystemIdentifier();
	list<GUID> getDependencies();

	EnginePointer<ID3D10Device> GetDevice();
	EnginePointer<IDXGISwapChain> GetSwapChain();

	AUTO_SIZE;
private:
	EnginePointer<WindowSystem> windowSystem;

	IDXGIFactory1 *pDXGIFactory;
	IDXGIAdapter *pAdapter;
	IDXGIOutput *pOutput;
	D3D10_DRIVER_TYPE driverType;
	EnginePointer<ID3D10Device> pDevice;
	EnginePointer<IDXGISwapChain> pSwapChain;

	HRESULT FindAdapter();
	HRESULT EnumerateModes();
	HRESULT InitializeDevice();
	HRESULT InitializeSwapChain();
	void SendGraphicsResizeMessages();
	void ResizeGraphics();
	void SendGraphicsResizedMessage();
	void SetFullscreen(BOOL fullscreen);
	void ToggleFullscreen();
};
